/* -+- file  ./kf2/Core/App.cs -+- */
/*
 * kf2 jabber client
 * ~~~~~~~~~~~~~~~~~
 *
 * Copyright (C) 2006-2007 Przemysław Sitek
 * 				<przemyslaw.sitek at wp.pl> 
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

using System;
using Mono.Unix;
using Habazie.kf2.GUI;
using Habazie.kf2.Net;

namespace Habazie.kf2.Core
{
	
	///<summary>Main application class</summary>
	public class App
	{
		///<summary>Application configuration</summary>
		private IConfiguration m_Config = null;
		
		private ConnectionManager m_Connections = null;
		
		private INotifyService m_NotifyService = null;
		
		private IArchivingService m_ArchiveService = null;
		
		private RosterWindow m_Window = null;
		
		public App()
		{
			Catalog.Init ("talkative", Util.FindFile ("locale"));
			
			m_Config = new GnomeConfiguration ();
			m_Config.Load ();
					
			m_Connections = new ConnectionManager (this);
			m_Connections.Load (Util.UserFile ("acc.xml"));
		//	m_Connections.Test ();
			
			m_NotifyService = new GtkNotify ();
			m_ArchiveService = new SqliteArchive ();
			
			m_Window = new RosterWindow (this);
			m_Window.Show ();


			/* Show account properties dialog on startup */
			if (m_Connections.Count == 0) {
				Account acc = new Account ();
				acc.Name = "New Account";
				acc.User = "";
				acc.Server = "";
				m_Connections.Add (acc);
				AccountDialog win = new AccountDialog (acc);
				win.Show ();
			}
		}
		
		#region Properties
		
		public IConfiguration Configuration {
			get { return m_Config; }
		}
		
		public ConnectionManager Connections {
			get { return m_Connections; }
		}
		
		public INotifyService NotifyService {
			get { return m_NotifyService; }
		}
		
		public IArchivingService ArchivingService {
			get { return m_ArchiveService; }
		}
		
		public RosterWindow MainWindow {
			get { return m_Window; }
		}
		
		#endregion	

		
		public void Shutdown ()
		{
			m_Connections.Store (Util.UserFile ("acc.xml"));
		}
	}

}
